package com.project.lk.nurseapp.nurse;

import android.content.ClipData;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.project.lk.nurseapp.R;
import com.project.lk.nurseapp.common.adapter.BaseRecycleViewAdapter;
import com.project.lk.nurseapp.nurse.model.ChatListItemBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 功能介绍：
 * 项目名：
 * 模块名称：
 * 作者：LK
 * 日期：2018/1/9
 * 修改日期：
 */
public class ChatListAdapter extends BaseRecycleViewAdapter {
    List<ChatListItemBean> mList = new ArrayList<>();
    Context mContext;

    public ChatListAdapter(List<ChatListItemBean> list, Context context) {
        this.mList = list;
        this.mContext = context;
    }

    public List<ChatListItemBean> getList(){
        return mList;
    }

    public void setList(List<ChatListItemBean> list){
        this.mList=list;
    }
    public interface ItemEventListenter{
        void comment(int position);
        void look(int position);
    }
    ItemEventListenter mListenter;
    public void setItemEvent(ItemEventListenter listenter){
        this.mListenter=listenter;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_msglist_layout, parent, false);
        ViewHolder viewHolder=new ViewHolder(view);
        return viewHolder;
    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {

        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.itemName.setText(mList.get(position).getNurseNickName()+","+mList.get(position).getDoctorNickName());
        viewHolder.itemTime.setText(mList.get(position).getCreateTime());
        if (TextUtils.equals(mList.get(position).getEvaluateStar(),"-1")) {
            viewHolder.itemComment.setVisibility(View.VISIBLE);
        }else {
            viewHolder.itemComment.setVisibility(View.GONE);
        }

        viewHolder.itemComment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListenter.comment(position);
            }
        });

        viewHolder.itemLook.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListenter.look(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.item_name)
        TextView itemName;
        @BindView(R.id.item_time)
        TextView itemTime;
        @BindView(R.id.item_look)
        TextView itemLook;
        @BindView(R.id.item_comment)
        TextView itemComment;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
